if( typeof console != 'undefined' ){ console.debug('mvl.js'); }

GW.pageOnLoad = function(){                                                     // onLoad
    GW.log.log( 'GW.pageOnLoad' );
    GW.newPage.init();                                                          // init new page facility.  Note IE will save space for dialogs if not inited!
    GW.displayFeaturePage.init();                                               // init feature page display facility
    GW.hash.init();                                                             // process the URL hash if any
    GW.mapDiv.init();
    GW.pageDiv.init();
    GW.listDiv.init();
    GW.wait.hide();
    GW.showDiv('');
};

GW.rte = {                                                                      // rich text editor routines
    editor: null,
    config: {                                                                   // YUI RTE editor config
        width: '702px',
        height: '525px',
        animate: true,
        dompath: true,
        filterWord: true,
        resize: true,
        focusAtStart: true,
        //
        toolbar: {
            grouplabels: false,                                                 // turn off group labels
            buttons: [
                { group: 'fontstyle', label: ' ',
                    buttons: [
                        { type: 'select', label: 'Arial', value: 'fontname', disabled: true,
                            menu: [
                                { text: 'Arial', checked: true },
                                { text: 'Arial Black' },
                                { text: 'Comic Sans MS' },
                                { text: 'Courier New' },
                                { text: 'Lucida Console' },
                                { text: 'Tahoma' },
                                { text: 'Times New Roman' },
                                { text: 'Trebuchet MS' },
                                { text: 'Verdana' }
                            ]
                        },
                        { type: 'spin', label: '13', value: 'fontsize', range: [ 9, 75 ], disabled: true }
                    ]
                },
                { type: 'separator' },
                { group: 'textstyle', label: ' ',
                    buttons: [
                        { type: 'push', label: 'Bold CTRL + SHIFT + B', value: 'bold' },
                        { type: 'push', label: 'Italic CTRL + SHIFT + I', value: 'italic' },
                        { type: 'push', label: 'Underline CTRL + SHIFT + U', value: 'underline' },
                        { type: 'separator' },
                        { type: 'color', label: 'Font Color', value: 'forecolor', disabled: true },
                        { type: 'color', label: 'Background Color', value: 'backcolor', disabled: true },
                        { type: 'separator' },
                        { type: 'push', label: 'Remove Formatting', value: 'removeformat', disabled: true },
                        { type: 'push', label: 'Show/Hide Hidden Elements', value: 'hiddenelements' }
                    ]
                },
                { type: 'separator' },
                { group: 'alignment', label: ' ',
                    buttons: [
                        { type: 'push', label: 'Align Left CTRL + SHIFT + [', value: 'justifyleft' },
                        { type: 'push', label: 'Align Center CTRL + SHIFT + |', value: 'justifycenter' },
                        { type: 'push', label: 'Align Right CTRL + SHIFT + ]', value: 'justifyright' },
                        { type: 'push', label: 'Justify', value: 'justifyfull' }
                    ]
                },
                { type: 'separator' },
                { group: 'parastyle', label: ' ',
                    buttons: [
                    { type: 'select', label: 'Normal', value: 'heading', disabled: true,
                        menu: [
                            { text: 'Normal', value: 'none', checked: true },
                            { text: 'Header 1', value: 'h1' },
                            { text: 'Header 2', value: 'h2' },
                            { text: 'Header 3', value: 'h3' },
                            { text: 'Header 4', value: 'h4' },
                            { text: 'Header 5', value: 'h5' },
                            { text: 'Header 6', value: 'h6' }
                        ]
                    }
                    ]
                },
                { type: 'separator' },
                { group: 'indent', label: ' ',
                    buttons: [
                        { type: 'push', label: 'Indent', value: 'indent', disabled: true },
                        { type: 'push', label: 'Outdent', value: 'outdent', disabled: true }
                    ]
                },
                { type: 'separator' },
                { group: 'list', label: ' ',
                    buttons: [
                        { type: 'push', label: 'Create an Unordered List', value: 'insertunorderedlist' },
                        { type: 'push', label: 'Create an Ordered List', value: 'insertorderedlist' }
                    ]
                },
                { type: 'separator' },
                { group: 'insertitem', label: ' ',
                    buttons: [
                        { type: 'push', label: 'HTML Link CTRL + SHIFT + L', value: 'createlink', disabled: true },
                        { type: 'push', label: 'Insert Image', value: 'insertimage' }
                    ]
                }
            ]
        }
    },
    init: function( onFunction ){                                               // init the RTE for editing the page content
        GW.rte.editor = new YAHOO.widget.Editor('idContentTA', GW.rte.config );
        GW.rte.editor.render();
        GW.rte.editor.on( 'editorContentLoaded', onFunction );
    },
    initOld: function(){                                                        // fix me when new code is working
        //hide and disable the non-dialog submit button:
        document.getElementById("submitButton").disabled = true;
        document.getElementById("submitButton").style.display = "none";
        //create the RTE:
        var editor = new YAHOO.widget.Editor('description', {
            width: '702px',
            height: '200px'
        });
        //After the Editor renders it, we will hide it
        //so the iframe doesn't bleed through
        editor.on('afterRender', editor.hide);
        //render the editor explicitly into a container
        //within the Dialog's DOM:
        editor.render();
        //create Dialog:
        var dlg = new YAHOO.widget.Dialog("idPageEditDialog", {
            width:"725px",
            fixedcenter:true,
            modal:true,
            visible:false
        });
        GW.rte.dlg = dlg;
        //event handlers for our Dialog buttons:
        //if the user clicks "save", then we save the HTML
        //content of the RTE and submit the dialog:
        function handleSave() {
            editor.saveHTML();
            this.submit();
        }
        //if the user clicks cancel, we call Dialog's
        //cancel method:
        function handleCancel() {
            this.cancel();
        }
        //set up buttons for the Dialog and wire them
        //up to our handlers:
        var myButtons = [ { text:"Save", 
            handler:handleSave },
        { text:"Cancel", 
            handler:handleCancel,
            isDefault:true } ];
        dlg.cfg.queueProperty("buttons", myButtons);
        //Dialog by default will use Connection Manager to POST
        //form contents to the URI specified in the action
        //attribute of the form; we can wire up success and
        //failure handlers for the XHR call and act on them
        //just as we would with any Connection Manager
        //transaction:
        var onSuccess = function(o) {
            //we're going to get JSON back from post.php; we
            //can parse it using JSON.parse:
            var data = YAHOO.lang.JSON.parse(o.responseText);
        //in this case, we'll just output the contents to 
        //a div to see what they contain:
        document.getElementById("responseContainer").innerHTML = 'Status: ' + 
            data.Results.status + 
            '<br>' + (new Date().toString());
        };
        var onFailure = function(o) {
            //in the event of a failure, we can log the problem:
            YAHOO.log("Dialog reported a communication failure; connection object: " + YAHOO.lang.dump(o, 5));
        };
        dlg.callback.success = onSuccess;
        dlg.callback.failure = onFailure;
        //Now that our Dialog is fully configured, we can
        //render it:
        dlg.render();
        //RTE needs a little love to work in in a Dialog that can be 
        //shown and hidden; we let it know that it's being
        //shown/hidden so that it can recover from these actions:
        dlg.showEvent.subscribe(editor.show, editor, true);
        dlg.hideEvent.subscribe(editor.hide, editor, true);
    },
    init2: function( content ){                                                 // finish rte initialization
        GW.log.log( 'rte init2' );
        GW.rte.editor.setEditorHTML( content );                                 // set content
        var div = document.getElementById( 'idLeft' );                          // the div holding the RTE
        var th = (GW.rte.editor.toolbar.get('element').clientHeight + 2);       // It has a 1px border.
        var dh = (GW.rte.editor.dompath.clientHeight + 1);                      // It has a 1px top border.
        var newH = (div.clientHeight - th - dh);
        GW.rte.editor.set('width', div.clientWidth + 'px' );
        GW.rte.editor.set('height', newH - 12 + 'px');
        GW.log.log( 'rte h ' + GW.vpHeight() + ' ' + GW.menu.height + ' ' + th + ' ' + dh + ' ' + newH);
    }
};

if( typeof console != 'undefined' ){ console.debug('mvl.js'); }
